﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;

namespace RaceGame2013
{
    class ScoreBoard
    {
        // Content manager etc
        ContentManager content;
        SpriteBatch spriteBatch;
        GraphicsDeviceManager graphics;

        // Reference to the car
        Voertuig vt;

        // Fonts
        SpriteFont font;

        // Rectangle
        Texture2D rect;

        // Constructor
        public ScoreBoard(ContentManager content, GraphicsDeviceManager graphics, SpriteBatch spriteBatch, Voertuig vt)
        { 
            // Reference
            this.content = content;
            this.graphics = graphics;
            this.spriteBatch = spriteBatch;
            this.vt = vt;

            // Create the rectangle
            rect = new Texture2D(graphics.GraphicsDevice, 80, 80);

        }

        // Load Content 
        public void LoadContent()
        { 
            // Load the font
            font = content.Load<SpriteFont>("Font");
        }

        // Update for the scoreboard
        public void Update()
        { 

        }

        // Draw the scoreboard
        public void Draw()
        {
            // Set the color for the new rectangle
            Color[] data = new Color[80 * 80];
            for (int i = 0; i < data.Length; ++i) data[i] = Color.WhiteSmoke;
            rect.SetData(data);

            // Set the postition
            Vector2 coor = new Vector2(vt.Position.X + 20, vt.Position.Y + 20);
            spriteBatch.Draw(rect, coor, Color.White);
           
            // Position of the string
            Vector2 pos = new Vector2(vt.Position.X + 22, vt.Position.Y + 22);

            // Making a new stringbuilder
            StringBuilder strScoreBoard = new StringBuilder();
            strScoreBoard.Append("Player " +vt.player.ToString() + "\n");
            strScoreBoard.Append("------------\n");
            strScoreBoard.Append("Health:" + vt.health.ToString() + "\n");
            strScoreBoard.Append("Laps:"+vt.laps + "\n");
            strScoreBoard.Append("Gas:" + ((int)vt.gas).ToString() + " %\n");
            strScoreBoard.Append("Speed:" + vt.Velocity*((100/3+21)) + "\n" );

            // Draw the string
            spriteBatch.DrawString(font, strScoreBoard, pos, Color.Black);
        }
    }
}
